package com.whfc.ms.api.fse.service.impl;

import com.whfc.common.file.FileHandler;
import com.whfc.common.file.FilePathConfig;
import com.whfc.common.result.PageData;
import com.whfc.common.util.RandomUtil;
import com.whfc.entity.dto.OssPathDTO;
import com.whfc.fse.param.FseResumeParam;
import com.whfc.fse.service.FseResumeService;
import com.whfc.ms.api.fse.service.MsFseResumeService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * @DESCRIPTION 特种设备履历
 * @AUTHOR hw
 * @DATE 2020/08/10
 */
@Service
public class MsFseResumeServiceImpl implements MsFseResumeService {

    @DubboReference(interfaceClass = FseResumeService.class, version = "1.0.0")
    private FseResumeService fseResumeService;

    @Autowired
    private FilePathConfig filePathConfig;

    @Autowired
    private FileHandler fileHandler;


    @Override
    public PageData<FseResumeParam> list(Integer fseId, Integer resumeType, Integer pageNum, Integer pageSize) {
        return fseResumeService.list(fseId, resumeType, pageNum, pageSize);
    }

    @Override
    public void add(FseResumeParam request) {
        fseResumeService.add(request);
    }

    @Override
    public void edit(FseResumeParam request) {
        fseResumeService.edit(request);
    }

    @Override
    public void del(Integer resumeId) {
        fseResumeService.del(resumeId);
    }

    @Override
    public OssPathDTO upload(MultipartFile file) {
        String upload = "";
        try {
            String originalFileName = file.getOriginalFilename();
            String suffix = originalFileName.substring(originalFileName.lastIndexOf(".") + 1);
            String path = filePathConfig.getFilePath("fse/resume/attach", RandomUtil.getRandomFileName(), suffix);
            InputStream inputStream = file.getInputStream();
            upload = fileHandler.upload(path, inputStream);
        } catch (Exception e) {

        }
        return new OssPathDTO(upload);
    }
}
